package enduringLink.call;

//零件销量对象，用于在RPC调用中统计销售总量
public class MyQuantityHandle implements QuantityHandle{
    private volatile long totalQuantity;
    private volatile int count;

    @Override
    public void addQuantity(long quantitySum) {
        add(quantitySum);
    }

    @Override
    public void setTotalQuantity(long totalQuantity) {
        this.totalQuantity = totalQuantity;
    }

    private synchronized void add(long quantitySum){
        totalQuantity += quantitySum;
        count++;
    }

    public boolean isCompletion(){
        return count == 4;
    }

    public long getTotalQuantity() {
        return totalQuantity;
    }
}
